package co.th.helper.jdbc.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import co.th.helper.jdbc.RowMapper;
import co.th.helper.model.Brand;
import co.th.helper.model.Category;
import co.th.helper.model.Product;

public class ProductRowMapper extends RowMapper<Product>{

	@Override
	public Product mapRow(ResultSet resultSet) throws SQLException {
		Product model = new Product();
		
		if (isThere(resultSet, "product_code")) {
			model.setProductCode(resultSet.getBigDecimal("product_code"));
		}
		
		if (isThere(resultSet, "product_year")) {
			model.setProductYear(resultSet.getBigDecimal("product_year"));
		}

		if (isThere(resultSet, "product_name_th")) {
			model.setProductNameTh(resultSet.getString("product_name_th"));
		}

		if (isThere(resultSet, "product_name_en")) {
			model.setProductNameEn(resultSet.getString("product_name_en"));
		}
		
		if (isThere(resultSet, "product_detail")) {
			model.setProductDetail(resultSet.getString("product_detail"));
		}
		
		if (isThere(resultSet, "image")) {
			model.setImage(resultSet.getBlob("image"));
		}
		
		if (isThere(resultSet, "category")) {
			model.setCategory(new Category(resultSet.getBigDecimal("category"), null, null));
		}
		
		if (isThere(resultSet, "brand")) {
			model.setBrand(new Brand(resultSet.getBigDecimal("brand"), null, null));
		}
		
		if (isThere(resultSet, "supplier")) {
			model.setSupplier(resultSet.getBigDecimal("supplier"));
		}
		
		if (isThere(resultSet, "active")) {
			model.setActive(resultSet.getString("active"));
		}

		if (isThere(resultSet, "create_by")) {
			model.setCreateBy(resultSet.getString("create_by"));
		}

		if (isThere(resultSet, "create_date")) {
			model.setCreateDate(resultSet.getDate("create_date"));
		}

		if (isThere(resultSet, "update_by")) {
			model.setUpdateBy(resultSet.getString("update_by"));
		}

		if (isThere(resultSet, "update_date")) {
			model.setUpdateDate(resultSet.getDate("update_date"));
		}
		
		return model;
	}

}
